package com.party.course.service.impl;

import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.hutool.core.date.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.party.course.mapper.AgreementInfoMapper;
import com.party.course.domain.AgreementInfo;
import com.party.course.service.IAgreementInfoService;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.party.common.utils.SecurityUtils;

/**
 * 教练端协议设置Service业务层处理
 *
 * @author ruoyi
 * @date 2025-06-04
 */
@Service
public class AgreementInfoServiceImpl extends ServiceImpl<AgreementInfoMapper, AgreementInfo> implements IAgreementInfoService {
    @Autowired
    private AgreementInfoMapper agreementInfoMapper;

    /**
     * 查询教练端协议设置
     *
     * @param id 教练端协议设置主键
     * @return 教练端协议设置
     */
    @Override
    public AgreementInfo view(String id) {
        return agreementInfoMapper.selectAgreementInfoById(id);
    }

    @Override
    public AgreementInfo findOne() {
        return agreementInfoMapper.findOne();
    }

    /**
     * 查询教练端协议设置列表
     *
     * @param agreementInfo 教练端协议设置
     * @return 教练端协议设置
     */
    @Override
    public List<AgreementInfo> findList(AgreementInfo agreementInfo) {
        return agreementInfoMapper.selectAgreementInfoList(agreementInfo);
    }

    /**
     * 新增教练端协议设置
     *
     * @param agreementInfo 教练端协议设置
     * @return 结果
     */
    @Override
    public int add(AgreementInfo agreementInfo) {
        AgreementInfo  info = agreementInfoMapper.findOne();
        if(ObjectUtil.isNotEmpty(info)){
            agreementInfo.setId(info.getId());
            agreementInfo.setUpdateTime(DateUtil.date());
            return agreementInfoMapper.updateById(agreementInfo);
        }else {
            agreementInfo.setId(IdUtil.simpleUUID());
            agreementInfo.setDelFlag("0");
            return agreementInfoMapper.insert(agreementInfo);
        }
    }

    /**
     * 修改教练端协议设置
     *
     * @param agreementInfo 教练端协议设置
     * @return 结果
     */
    @Override
    public int updateEntity(AgreementInfo agreementInfo) {
        agreementInfo.setUpdateTime(DateUtil.date());
        return agreementInfoMapper.updateById(agreementInfo);
    }

    /**
     * 批量删除教练端协议设置
     *
     * @param ids 需要删除的教练端协议设置主键
     * @return 结果
     */
    @Override
    public int deleteIds(List<String> ids) {
        return agreementInfoMapper.deleteAgreementInfoByIds(ids);
    }

    /**
     * 删除教练端协议设置信息
     *
     * @param id 教练端协议设置主键
     * @return 结果
     */
    @Override
    public int deleteById(String id) {
        return agreementInfoMapper.deleteAgreementInfoById(id);
    }
}
